{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 什么是迭代协议\n",
    "## 迭代器是什么\n",
    "\n",
    "## 迭代器：是访问集合内元素的一种方式\n",
    "## 迭代器和以下标的访问方式不一样，迭代器是不能返回的，迭代器提供了一种惰性方式 数据的方式\n",
    "## [] list, __iter__\n",
    "## 实现__iter__为可迭代\n",
    "## 迭代器需要实现__next__方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from collections.abc import Iterable, Iterator\n",
    "\n",
    "# list 可迭代，但不是迭代器\n",
    "a = [1, 2]\n",
    "print(isinstance(a, Iterable))\n",
    "print(isinstance(a, Iterator))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
